package com.prj.ufdm.web.bpo._impl;

import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.prj.ufdm.core.util.UfdmDateUtil;
import com.prj.ufdm.web.bpo.SysUserBPO;
import com.prj.ufdm.web.constant.AuthUrlConstants;
import com.prj.ufdm.web.model.SysUser;
import com.prj.ufdm.web.util.AuthRestTemplateUtil;

/**
 * 系统用户管理
 */
@Service 
public class SysUserBPOImpl  implements SysUserBPO {
	
	@Autowired
	AuthRestTemplateUtil authRestTemplateUtil;
	
	public SysUser modifyById(SysUser sysUser) throws Exception {
		if(sysUser==null || sysUser.getId()==null || sysUser.getToken()==null || sysUser.getUsername()==null ) {
			return null;
		}
		Map<String,String> paramMap = new HashMap<String,String>();
		paramMap.put("id", sysUser.getId());
		paramMap.put("token", sysUser.getToken());
		paramMap.put("username", sysUser.getUsername());
		paramMap.put("tokenCreateTime", UfdmDateUtil.getCurrentTime());
		SysUser rtnSysUser = authRestTemplateUtil.doAuthParamPostForObject(AuthUrlConstants.MODIFY_SYSUSER, paramMap, null, SysUser.class);
    	return rtnSysUser;
	}

	@Override
	public SysUser doGetSysUserByUsername(String username) throws Exception {
		if(username==null || username.equals("")) {
			return null;
		}
		Map<String,String> paramMap = new HashMap<String,String>();
		paramMap.put("username",username);
		SysUser sysUser = authRestTemplateUtil.doAuthParamPostForObject(AuthUrlConstants.GET_SYSUSER_BY_USERNAME, paramMap, null, SysUser.class);
    	return sysUser;
	}

	@Override
	public SysUser doGetSysUserByToken(String token) throws Exception {
		if(token==null || token.equals("")) {
			return null;
		}
		Map<String,String> paramMap = new HashMap<String,String>();
		paramMap.put("token",token);
		SysUser sysUser = authRestTemplateUtil.doAuthParamPostForObject(AuthUrlConstants.GET_SYSUSER_BY_TOKEN, paramMap, null, SysUser.class);
    	return sysUser;
	}

}
